package com.Smart.smartscals.Utils;

import android.content.Context;
import android.database.Cursor;

import com.Smart.smartscals.DataBase.DataBaseService;
import com.Smart.smartscals.Entity.EntityReciveBodyInfo;


public class SeletLastDataBaseUtilt {
	Context context;
	DataBaseService mDataService;
	public SeletLastDataBaseUtilt(Context context){
		this.context = context;
	}
	public EntityReciveBodyInfo getLastBodyInfoEntity(String muserName){
		
		mDataService = DataBaseService.getInstance(context);
		Cursor lastCursor = mDataService.getLastData(muserName);
		EntityReciveBodyInfo lastBodyInfoEntity = new EntityReciveBodyInfo();
		if(lastCursor.moveToLast()){
			
			lastBodyInfoEntity.setDate(lastCursor.getLong(lastCursor.getColumnIndex("date")));
			lastBodyInfoEntity.setWeight(lastCursor.getFloat(lastCursor.getColumnIndex("weight")));
			lastBodyInfoEntity.setBodyFat(lastCursor.getFloat(lastCursor.getColumnIndex("bodyFat")));
			lastBodyInfoEntity.setWeekNUM(lastCursor.getInt(lastCursor.getColumnIndex("weekNUM")));
			lastBodyInfoEntity.setMonthNUM(lastCursor.getInt(lastCursor.getColumnIndex("monthNUM")));
			lastBodyInfoEntity.setDayNUM(lastCursor.getInt(lastCursor.getColumnIndex("dayNUM")));
			lastBodyInfoEntity.setYearNUM(lastCursor.getInt(lastCursor.getColumnIndex("yearNUM")));
			lastBodyInfoEntity.setUserName(lastCursor.getString(lastCursor.getColumnIndex("userName")));
		}
		if(lastCursor!=null){
			lastCursor.close();
		}
		
		return lastBodyInfoEntity;
	}

}
